import {fetch} from 'utils/fetch';

/***
 * 极验初始化
 * @param data
 * POST
 * @returns {*}
 */
export function geetByCode(data) {
	return fetch({
		url: '/user/geetestStartCaptcha',
		method: 'POST'
	});
}

/***
 * 极验生成圖片
 * @param data
 * @returns {*}
 */
export function generateVerificationCode(data) {
	return fetch({
		url: '/register/generateVerificationCode',
		method: 'POST',
		data
	});
}

/***
 * POST 发送短信验证码
 * @param data
 * @returns {*}
 */
export function sendVeriCode(mobile, prefix) {
	return fetch({
		url: '/user/sendVeriCode?mobile=' + mobile + '&prefix=' + prefix,
		method: 'POST'
	});
}

/***
 * 注册
 * @param data
 * @returns {*}
 */
export function register(data) {
	return fetch({
		url: '/user/register',
		method: 'POST',
		data
	});
}

/***
 * POST 静默注册
 * @param data
 * @returns {*}
 */
export function silentRegistration(data) {
	return fetch({
		url: '/user/silentRegistration',
		method: 'POST',
		data
	});
}

/***
 * 登陆
 * @param data
 * @returns {*}
 */
export function loginIn(data) {
	data['appCode'] = 'WMR';
	//密码登录
	if (data.hasOwnProperty('password')) {
		return fetch({
			url: '/user/login',
			method: 'POST',
			data
		});
	} else {//手机验证码登录
		return fetch({
			url: '/user/loginByCode',
			method: 'POST',
			data
		});
	}
}

/***
 * 登出
 * @param data
 * @returns {*}
 */
export function logout() {
	return fetch({
		url: '/user/logout',
		method: 'POST'
	});
}

/***
 * 获取当前用户信息
 * @param data
 * @returns {*}
 */
export function getInfo() {
	return fetch({
		url: '/auth/currentUser',
		method: 'POST'
	});
}

/***
 * 忘记密码
 * @param data
 * @returns {*}
 */
export function forgetPassword(data) {
	return fetch({
		url: '/loanApply/forgetPassword',
		method: 'POST',
		data
	});
}

/***
 * 重置密码
 * @param data
 * @returns {*}
 */
export function resetPassword(data) {
	return fetch({
		url: '/register/resetPassword',
		method: 'POST',
		data
	});
}

/***
 * 刷新缓存
 * @param data
 * @returns {*}
 */
export function reFlushcCurrentUser(data) {
	return fetch({
		url: '/auth/reFlushcCurrentUser',
		method: 'post'
	});
}

/***
 * 更新用户信息
 * @param data
 * @returns {*}
 */
export function updateCurrentUser(uscCode) {
	return fetch({
		url: '/certification/getUserInfo?uscCode='+uscCode,
		method: 'post'
	});
}
/***
 * 获取token
 * @param data
 * @returns {*}
 */
export function queryToken() {
	return fetch({
		url: '/zt/getZtToken',
		method: 'post'
	});
}
//静默登录
export function ztLogin(authCode) {
	return fetch({
		url: '/zt/login?authCode='+authCode,
		method: 'post'
	});
}
